import asyncio
from zipstream import AioZipStream
from aiofile import async_open


async def content_generator():
    yield b'foo baz'
    asyncio.sleep(0.1)  # we simulate little slow source of data
    data = await remote_data_source()
    yield bytes(data, 'utf-8')  # always remember to yield binary data
    asyncio.sleep(0.5)
    yield b"the end"


async def zip_async(zipname, files):
    aiozip = AioZipStream(files, chunksize=32768)
    async with async_open(zipname, mode='wb') as z:
        async for chunk in aiozip.stream():
            await z.write(chunk)


files = [
    {'file': '/tmp/car.jpeg'},
    {'file': '/tmp/aaa.mp3', 'name': 'music.mp3'},
    {'stream': content_generator(),
     'name': 'random_stuff.txt'}
]
